<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="所属公司" @keyup.enter.native="getList">
        <treeSelect  size="small"  @department="departmentChange" :model="queryParams.departmentName" type="department"></treeSelect>
      </el-form-item>
      <el-form-item label="调拨单号" >
        <el-input
          v-model="queryParams.allotCode"
          placeholder="请输入调拨单号"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="申请人" >
        <el-input
          v-model="queryParams.createByName"
          placeholder="请输入申请人"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="采购类型" >
        <el-select
          v-model="queryParams.examineState"
          placeholder="采购类型"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in cglxList"
            :key="dict.dictValue"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态" >
        <el-select
          v-model="queryParams.examineState"
          placeholder="审核状态"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="申请时间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          @change="timechange(dateRange)"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="getList">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="roleList" stripe >
      <el-table-column align="center" type="index" label="序号"  width="55"  />
      <el-table-column align="center" label="调拨单号" property="allotCode" width="150" >
        <template slot-scope="scope" style="text-align: center">
          <span style="color: #2196F3;cursor: pointer" @click="xingqing(scope.row.id)">{{scope.row.allotCode}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="申请时间"   property="applyTime"   ></el-table-column>
      <el-table-column align="center" label="申请人" property="createByName"  ></el-table-column>
      <el-table-column label="备注" property="remark" align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column align="center" label="审核状态"  property="examineState" :show-overflow-tooltip="true"  >
        <template slot-scope="scope" style="text-align: center">
          <div style="background:#78BF34  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row. examineState=='0'" >未提交</div>
          <div style="background:#78BF34  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row. examineState=='1'" >进行中</div>
          <div style="background:#9E71DC  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row. examineState=='2'">已结束</div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="审核结束时间" property="examineEndTime" :show-overflow-tooltip="true"  ></el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="200">
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="danger"
            icon="el-icon-refresh-right"
            v-show="scope.row.examineState=='0'"
            @click="handleDelete(scope.$index, scope.row)">编辑</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
  import request from '@/utils/request'
  import treeSelect from '../equipmentGL/equipmentTZ/treeSelect'

  export default {
    name: "Role",
    components:{
      treeSelect,
    },
    data() {
      return {
        ssbmOptions:undefined,
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 角色表格数据
        roleList: [],
        // 日期范围
        dateRange: [],
        //采购类型
        cglxList:[
          { value: '1',label: '调拨'},
          { value: '2',label: '转移'},
        ],
        // 状态数据字典
        statusOptions: [
          { value: '0',label: '未提交'},
          { value: '1',label: '进行中'},
          { value: '2',label: '已结束'},

        ],
        // 数据范围选项
        dataScopeOptions: [
          {
            value: "1",
            label: "全部数据权限"
          },
          {
            value: "2",
            label: "自定数据权限"
          },
          {
            value: "3",
            label: "本部门数据权限"
          },
          {
            value: "4",
            label: "本部门及以下数据权限"
          },
          {
            value: "5",
            label: "仅本人数据权限"
          }
        ],
        // 菜单列表
        menuOptions: [],
        // 部门列表
        deptOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          allotCode:'',
          beginApplyTime:'',
          createByName:'',
          deptId:'',
          endApplyTime:'',
          examineState:'',

        },
        // 表单参数
        form: {},
        defaultProps: {
          children: "children",
          label: "label"
        },
      };
    },
    created() {

      this.getList()

    },
    methods: {
      //时间监听
      timechange:function(row){
        console.log(row)
        this.queryParams.beginApplyTime = row[0]
        this.queryParams.endApplyTime = row[1]
      },
      /** 获取所属部门的值*/
      departmentChange(data) {
        this.queryParams.deptId = data.id
        this.queryParams.departmentName=data.label
        this.getList()
      },
      /** 查询角色列表 */
      getList() {
        console.log('111',this.queryParams)
        this.loading = true;
        request({
          url: '/device-allot-api/myApproval',
          method: 'get',
          params:this.queryParams
        }).then(response => {
          this.loading = false;
          this.roleList = response.rows
          this.total = response.total
        });
      },
      //表格编辑
      handleEdit:function (index,row) {
        console.log(row)
        var obj={
          name:'采购计划'
        }
        this.$router.push({path:'/purchaseGL/cgjhAdd',query:{data:obj}});
      },
      //删除
      handleDelete:function (index,row) {
        this.$confirm('确定撤销该数据吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message({
            type: 'success',
            message: '撤销成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消撤销'
          });
        });
      },
      //采购计划
      cgjhadd:function () {
        this.$router.push({path:'/equipmentCZ/dialEdit',query:{userid:'55555'}});
      },
      //详情点击
      xingqing:function (row) {
        this.$router.push({path:'/equipmentCZ/dbzyDetail',query:{data:row}});
      },

    }
  };
</script>
